package com.itheima.day06AIPI.Demo5;

import java.util.ArrayList;
import java.util.Objects;

/*9、【编号：1208】某公司发放年终礼品，但hr
在统计的时候发现有很多同姓名同年龄的员工，
所以决定对这一部分员工，发放【缘分大礼包】，
其余员工发放【普通大礼包】，请用技术手段，
完成礼品的分发。 现有4个员工信息：
张三，23
李四，24
张三，23
张三，28
运行结果：
Employee{name=张三,age=23}获得了缘分大礼包
Employee{name=李四,age=24}获得了普通大礼包
Employee{name=张三,age=23}获得了缘分大礼包
Employee{name=张三,age=28}获得了普通大礼包*/
public class Demo5 {
    public static void main(String[] args) {
        ArrayList<Employee1> list = new ArrayList<Employee1>();
        list.add(new Employee1("张三", 23));
        list.add(new Employee1("李四", 24));
        list.add(new Employee1("张三", 23));
        list.add(new Employee1("张三", 28));
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i).toString());
            for (int j = 0; j < list.size(); j++) {
                if (i != j && list.get(i).equals(list.get(j))) {
                    System.out.println("获得了缘分大礼包");
                    break;
                }
                if (j == list.size()-1) {
                    System.out.println("获得了普通大礼包");
                }
            }
        }

    }
}

class Employee1 {
    private String name;
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Employee1() {
    }

    public Employee1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee1 employee = (Employee1) o;
        return age == employee.age &&
                Objects.equals(name, employee.name);
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}